﻿using Tszy.Unlimited.Data.FreeSQL;

using static Tszy.Examples.Database.FreeSQLs.FreeSQLTest;

namespace Tszy.Examples.Database.FreeSQLs;

public class FreeSQLDbContextService
{
    private readonly FreeSqlDbContext _context;

    public FreeSQLDbContextService(FreeSqlDbContext context)
    {
        _context = context;
    }

    public async Task ExecuteAsync()
    {
        await _context.Set<TestUser>().AddAsync(new TestUser("tszy", "1234566"));
        var user = await _context.Set<TestUser>().Select.Where(item => item.Id == 7).FirstAsync();
        //var user = await _context.Set<TestUser>().Select.ForUpdate().Where(item => item.Id == 7).FirstAsync();
        await _context.Orm.GetGuidRepository<TestUser>().UpdateDiy.Set(item => item.Money + 1).Where(item => item.Id == 7).ExecuteAffrowsAsync();
        //user.Money += 10;
        //await _context.Set<TestUser>().UpdateAsync(user);
        await _context.SaveChangesAsync();
    }
}